home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Files / Standard File / CustomGet unresolved alias / CustomGet unresolved alias.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.5 KB  |  129 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        CustomGet unresolved alias.c
  3.  
  4.     Contains:    This sample demonstrates how to let the user choose an alias file
  5.                 from an "open" dialog. The basic idea is to intercept the pseudo-
  6.                 item 'sfHookOpenAlias' in a CustomGetFile hook function and transform
  7.                 it into 'getOpen'. This causes the dialog to behave as if the user
  8.                 had clicked the open button. Also, we intercept the item number of
  9.                 a check box we have added to the dialog item template in order to
  10.                 allow the user to choose whether to resolve aliases. Finally,
  11.                 when CustomGetFile returns, we call Alert to let the user know
  12.                 what happened.
  13.  
  14.     Written by: Pete Gontier    
  15.  
  16.     Copyright:    Copyright © 1999 by Apple Computer, Inc., All Rights Reserved.
  17.  
  18.                 You may incorporate this Apple sample source code into your program(s) without
  19.                 restriction. This Apple sample source code has been provided "AS IS" and the
  20.                 responsibility for its operation is yours. You are not permitted to redistribute
  21.                 this Apple sample source code as "Apple sample source code" after having made
  22.                 changes. If you're going to re-distribute the source, we require that you make
  23.                 it clear in the source that the code was descended from Apple sample source
  24.                 code, but that you've made changes.
  25.  
  26.     Change History (most recent first):
  27.                 7/1/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  28.                 03/22/96                    Use an alert, not DebugStr
  29.                 03/22/96                    in DlgHookYDProc, make sure we're dealing with
  30.                                             main dialog before doing anything interesting
  31.                 01/30/95                    use AppendDITL instead of copy of System resources
  32.                 01/25/95                    initial version
  33.     
  34.                 
  35.  
  36. */
  37. #define OLDROUTINELOCATIONS        0
  38. #define OLDROUTINENAMES            0
  39. #define SystemSevenOrLater        1
  40.  
  41. #ifndef __FONTS__
  42. #    include <Fonts.h>
  43. #endif
  44.  
  45. #ifndef __DIALOGS__
  46. #    include <Dialogs.h>
  47. #endif
  48.  
  49. #ifndef __STANDARDFILE__
  50. #    include <StandardFile.h>
  51. #endif
  52.  
  53. #ifndef __RESOURCES__
  54. #    include <Resources.h>
  55. #endif
  56.  
  57. static pascal OSErr InitMac (void)
  58. {
  59.     MaxApplZone ( );
  60.     InitGraf (&(qd.thePort));
  61.     InitFonts ( );
  62.     InitWindows ( );
  63.     InitMenus ( );
  64.     TEInit ( );
  65.     InitDialogs (nil);
  66.  
  67.     return noErr;
  68. }
  69.  
  70. static short gItemIndex_CustomGetCheckBox;
  71.  
  72. enum
  73. {
  74.     kResID_CustomGetCheckBox = 128,
  75.     kResID_ReportResultsAlert
  76. };
  77.  
  78. static pascal short DlgHookYDProc (short item, DialogRef dRef, void *)
  79. {
  80.     if (GetWRefCon (dRef) == sfMainDialogRefCon)
  81.     {
  82.         if (item == sfHookFirstCall)
  83.         {
  84.             Handle checkBoxDitlH = GetResource ('DITL',kResID_CustomGetCheckBox);
  85.             if (!ResError ( ) && checkBoxDitlH)
  86.             {
  87.                 DetachResource (checkBoxDitlH);
  88.                 if (ResError ( ))
  89.                     ReleaseResource (checkBoxDitlH);
  90.                 else
  91.                 {
  92.                     gItemIndex_CustomGetCheckBox = 1 + CountDITL (dRef);
  93.                     AppendDITL (dRef,checkBoxDitlH,appendDITLBottom);
  94.                     DisposeHandle (checkBoxDitlH);
  95.                 }
  96.             }
  97.         }
  98.         else if (item == gItemIndex_CustomGetCheckBox || item == sfHookOpenAlias)
  99.         {
  100.             short iType; Rect iRect; Handle iHandle; Boolean iValue;
  101.             GetDialogItem (dRef,gItemIndex_CustomGetCheckBox,&iType,&iHandle,&iRect);
  102.             iValue = GetControlValue ((ControlRef) iHandle);
  103.             if (item != sfHookOpenAlias)
  104.                 SetControlValue ((ControlRef) iHandle, !iValue);
  105.             else if (!iValue)
  106.                 item = getOpen;
  107.         }
  108.     }
  109.  
  110.     return item;
  111. }
  112.  
  113. void main (void)
  114. {
  115.     if (!InitMac ( ))
  116.     {
  117.         StandardFileReply sfr;
  118.         Point sfWhere = {-1,-1};
  119.         CustomGetFile (nil,-1,nil,&sfr,sfGetDialogID,sfWhere,NewDlgHookYDProc(DlgHookYDProc),nil,nil,nil,nil);
  120.  
  121.         if (sfr.sfGood)
  122.             ParamText (sfr.sfFile.name,nil,nil,nil);
  123.         else
  124.             ParamText ("\pAs the world's worst singer would say: 'No reply at all.'",nil,nil,nil);
  125.  
  126.         Alert (kResID_ReportResultsAlert,nil);
  127.     }
  128. }
  129.